package com.realtyManage.springboot.Dao;


import com.realtyManage.springboot.Model.Do.ProjectAssort;
import com.realtyManage.springboot.Model.Do.ProjectExhibition;
import io.lettuce.core.dynamic.annotation.Param;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;

/**
 * 展示信息
 *
 * @author 杭州素色网络科技有限公司
 * @since 2019-10-15
 */

@Repository
public interface ProjectExhibitionRepository extends JpaRepository<ProjectExhibition, Integer>, JpaSpecificationExecutor<ProjectExhibition> {

    @Transactional
    @Modifying
    @Query("update ProjectExhibition a set " +
            "a.position = CASE WHEN :#{#projectExhibition.position} IS NULL THEN a.position ELSE :#{#projectExhibition.position} END ," +
            "a.releaseUserId = CASE WHEN :#{#projectExhibition.releaseUserId} IS NULL THEN a.releaseUserId ELSE :#{#projectExhibition.releaseUserId} END ," +
            "a.releaseTime = CASE WHEN :#{#projectExhibition.releaseTime} IS NULL THEN a.releaseTime ELSE :#{#projectExhibition.releaseTime} END ," +
            "a.updateUserId = CASE WHEN :#{#projectExhibition.updateUserId} IS NULL THEN a.updateUserId ELSE :#{#projectExhibition.updateUserId} END ," +
            "a.updateTime = CASE WHEN :#{#projectExhibition.updateTime} IS NULL THEN a.updateTime ELSE :#{#projectExhibition.updateTime} END ," +
            "a.title = CASE WHEN :#{#projectExhibition.title} IS NULL THEN a.title ELSE :#{#projectExhibition.title} END ," +
            "a.content = CASE WHEN :#{#projectExhibition.content} IS NULL THEN a.content ELSE :#{#projectExhibition.content} END ," +
            "a.img = CASE WHEN :#{#projectExhibition.img} IS NULL THEN a.img ELSE :#{#projectExhibition.img} END " +
            "where a.id = :#{#projectExhibition.id}")
    int updateProjectExhibition(@Param("projectExhibition") ProjectExhibition projectExhibition);

}
